package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.Store;
import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.query.GrogshopQuery;
import cn.wolfcode.trip.base.query.StoreQuery;
import cn.wolfcode.trip.base.service.IStoreService;
import cn.wolfcode.trip.base.util.JsonResult;
import cn.wolfcode.trip.base.util.UploadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

/**
 * 积分商城
 */
@Controller
@RequestMapping("store")
public class StoreController {
    @Autowired
    private IStoreService storeService;

    @RequestMapping("list")
    public String list(@ModelAttribute("qo") StoreQuery qo, Model model){
        model.addAttribute("pageInfo",storeService.query(qo));
        return "store/list";
    }

    @RequestMapping("updateShelves")
    @ResponseBody
    public JsonResult updateShelves(Store store){
        storeService.updateShelves(store);
        return new JsonResult();
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(MultipartFile file, Store store){
        JsonResult jsonResult = new JsonResult();
        if (file!=null && file.getSize()>0){
            //保存封面图片
            String url = UploadUtil.uploadQiniu(file);
            //把url设置到coverUrl属性
            store.setPicture(url);
        }
        storeService.saveOrUpdate(store);
        return jsonResult;
    }
}
